import React, { Component } from 'react'
import ReactDOM from 'react-dom';
import { Modal, Form, message, Table, Button } from 'antd';
import { ModalForm } from '../../../components'
import { fetchData } from '../../../components/AjaxConsumer'

export default class InfoPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            visible: false,
            dataSource: null,

            sortedInfo: null,
            conditonData: {}
        };


    }

    renderColumns(text) {
        if (text == '0') {
            return (<span>正品</span>);
        } else if (text == '1') {
            return (<span>样品</span>);
        } 
    }

    renderColumns1(text) {
        if (text == '2') {
            return (<span>质量冻结</span>);
        } else if (text == '4') {
            return (<span>手工冻结</span>);
        } else if (text == '1') {
            return (<span>抽检冻结</span>);
        } else if (text == '3') {
            return (<span>调拨冻结</span>);
        }
    }

    //显示弹框
    showModal = () => {
        this.setState({
            visible: true,
        });
    }
    // 隐藏弹出框
    hideModal = () => {
        this.setState({
            visible: false,
        });
    }

    handleOk = () => {
        this.setState({
            visible: false,
        });
        this.refreshHandle();
    }

    handleCancel = () => {
        this.setState({
            visible: false,
            sortedInfo: null
        });

    }

    //刷新List列表
    refreshHandle = () => {
        console.log("刷新List列表")
        this.props.refreshHandle();
    }

    onClickDC = () => {
        console.log("daochu")
        let conditonData = this.state.conditonData;
        // console.log('-------导出条件--------',conditonData); 
        let param = '?'
        for (let key in conditonData) {
            if (conditonData[key] != '') {
                console.log(key, conditonData[key]);
                param = param + key + '=' + conditonData[key] + '&'
            }
        }
        console.log(param);
        window.location.href = '/wmsrest/product/odsprostoragesn/r/detail/exp' + param;
    }

    // (外部调用)
    editHandle = (resData, pstData) => {
        this.setState({
            visible: true,
            formTitle: '盘点记录详情',
            dataSource: resData.data,
            conditonData: pstData
        });
        console.log("pstData", pstData)
    }

    render() {
        this.columns = [
            {
                title: '盘点单号',
                dataIndex: 'countingCode',
                width: '11%',
                render(text) {
                    return <span title={text}>{text}</span>
                }
            }, {
                title: '盘点时间',
                dataIndex: 'countingTime',
                width: '13%',
                render(text) {
                    return <span title={text}>{text}</span>
                }
            }, 
            {
                title: '条码',
                dataIndex: 'barcode',
                // sorter:(a,b)=>a.proBarcode.substr(a.proBarcode.length-2)-b.proBarcode.substr(a.proBarcode.length-2),
                width: '10%',
                render(text) {
                    return <span title={text}>{text}</span>
                }
            }, {
                title: '型号',
                dataIndex: 'model',
                width: '10%',
                render(text) {
                    return <span title={text}>{text}</span>
                }
            },{
                title: '型号描述',
                dataIndex: 'modelDesc',
                width: '10%',
                render(text) {
                    return <span title={text}>{text}</span>
                }
            },{
                title: '型号类型',
                dataIndex: 'modelType',
                width: '8%',
                render: (text, record, index) => this.renderColumns(text),
            },{
                title: '仓库',
                dataIndex: 'whCode',
                width: '8%',
                render(text) {
                    return <span title={text}>{text}</span>
                }
            }, {
                title: '区域',
                dataIndex: 'wdCode',
                width: '8%',
                render(text) {
                    return <span title={text}>{text}</span>
                }
            },{
                title: '库区',
                dataIndex: 'waCode',
                width: '8%',
                render(text) {
                    return <span title={text}>{text}</span>
                }
            },{
                title: '库位',
                dataIndex: 'wlCode',
                width: '8%',
                
            },{
                title: '保管员',
                dataIndex: 'keepBy',
                width: '9%',
                
            }
        ];
        return (

            <Modal
                style={{ top: '20px' }}
                visible={this.state.visible}
                title={this.state.formTitle ? this.state.formTitle : '填写表单'}
                onOk={this.handleOk}
                onCancel={this.handleCancel}
                width={'1100px'}
                footer=''

            >
                {/* <Button type="Excel" onClick={this.onClickDC}>Excel</Button> */}
                <div style={{ margin: '10px' }}>
                    {
                        <Table columns={this.columns}
                            dataSource={this.state.dataSource}
                            rowKey={row => row.odsProStorageSnId}
                            showHeader={true}
                            pagination={{ pageSize: 10, size: 'default' }}

                            //scroll={{ y: 380 }}
                            size="small"
                            bordered
                        />
                    }
                </div>

            </Modal>
        )
    }
}